#include <iostream>
#include "chrono"
#include "ctime"

#include "../soft_timer.h"

/**
 * 毫秒时间戳
 * @return
 */
uint32_t get_tick() {
    auto now = std::chrono::system_clock::now();
    auto duration = now.time_since_epoch();

    return static_cast<uint32_t> (std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
}

void callback(soft_timer_t *timer){
    auto now = std::chrono::system_clock::now();

    std::time_t now_time = std::chrono::system_clock::to_time_t(now);

    std::cout << "hello world    " << std::ctime(&now_time) << std::endl;
}

int main() {
    soft_timer_init(get_tick);
    soft_timer_create("timer", 1000, callback, NULL);

    for(;;) {
        soft_timer_handler();
    }
}

